<template>
  <div class="flex flex-col gap-2">
    <NInput v-model:value="title" placeholder="请输入标题" />
    <NInput v-model:value="content" type="textarea" placeholder="请输入内容" :rows="6" />
    <NButton @click="handleSubmit">提交</NButton>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useMessage } from 'naive-ui';
import { useFetch } from '@vueuse/core';
import { useRouterPush } from '~/src/composables';
const title = ref('');
const content = ref('');
const message = useMessage();
async function handleSubmit() {
  if (!title.value || !content.value) {
    message.warning('忘了输入了哦');
    return;
  }
  await useFetch(`${import.meta.env.VITE_API}/knowledge`)
    .post({
      title: title.value,
      content: content.value
    })
    .json();
  message.info('已发送');
  useRouterPush(false).routerPush('/knowledge/manage');
}
</script>
